#include <REGX52.H>
#include <INTRINS.H>
#include "Delay.h"
#include "Key.h"
#include "timer0.h"
#include "LCD1602.h"
#include "Nixie.h"


void main()
{
	unsigned char Key_Num = 0;
	
	Timer0_Init();
	P2 = 0xff;
	LCD_Init();
	
	LCD_ShowString(1,1,"Hello!");
	
	
	Nixie_Setbuffer(1, 1);
	Nixie_Setbuffer(2, 2);
	Nixie_Setbuffer(3, 3);
	Nixie_Setbuffer(4, 4);
	Nixie_Setbuffer(5, 5);
	Nixie_Setbuffer(6, 6);
	Nixie_Setbuffer(7, 7);
	Nixie_Setbuffer(8, 8);
	while(1)
	{
		Key_Num = Key();
		if(Key_Num){
			LCD_ShowNum(2,1,Key_Num,5);
		}
		
		Delay(1000);
	}
}


/**
  * @brief  定时器0中断处理函数模版
  * @param  无
  * @retval 无
  */
void Timer_Routine(void) interrupt 1
{
	static unsigned int key_count = 0;
	static unsigned int nixie_count = 0;
	static unsigned char toggle = 0;
	
	key_count++;
	
	if(key_count >= 20)
	{
		Key_Loop();
		key_count = 0;		
	}
	
	
	nixie_count++;
	if(nixie_count >= 2)
	{
		Nixie_Loop();
		nixie_count = 0;		
	}
	
	
	//定时器溢出之后需要重新装载
	TH0 = (65535 - 1000) / 256;					//12MHz晶振，12分频
	TL0 = (65535 - 1000) % 256 + 1; 			//
}